package com.xiaoye.component;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 宵夜
 * @version 1.0.0
 * @Description: 登录拦截器，用于登录检查，权限控制
 */
public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object user = request.getSession().getAttribute("loginUser");

        if ((user == null)){
            //未登录，返回report界面
            response.sendRedirect("/report/");
            return false;
        }else {
            //一登陆，放行
            return true;
        }
    }
}
